package master

import (
	"net"
	"net/http"
	"time"
)

//任务的Http接口
type ApiServer struct{
	httpServer *http.Server

}
var(
	G_apiServer *ApiServer
)
//保存任务接口
func handleJobSave(w http.ResponseWriter,r *http.Request){

}
//初始化服务
func InitApiServer() error {
	var(
		mux *http.ServeMux
		listener net.Listener
		httpServer *http.Server
		err error
	)
	//配置路由
	mux = http.NewServeMux()
	mux.HandleFunc("/job/save",handleJobSave)
	//启动TCP监听
	if listener,err =net.Listen("tcp",":8070");err!=nil{
		return nil
	}

	//创建一个HTTP服务
	httpServer = &http.Server{
		Addr:              "",
		Handler:           mux,
		ReadTimeout:       5 *time.Second,
		WriteTimeout:      5 *time.Second,

	}
	G_apiServer = &ApiServer{
		httpServer:httpServer,
	}
	go httpServer.Serve(listener)

	return err
}